package cn.iocoder.boot.springai001.tools.vo;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;

/**
 * Text2SQL智能体查询响应VO
 */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Schema(description = "Text2SQL智能体查询响应")
public class Text2SqlAgentQueryRespVO {

    @Schema(description = "是否成功", example = "true")
    private Boolean success;

    @Schema(description = "SQL查询结果（JSON格式）")
    private String result;

    @Schema(description = "生成的SQL语句")
    private String generatedSql;

    @Schema(description = "识别的相关表名")
    private List<String> tableNames;

    @Schema(description = "执行步骤数", example = "6")
    private Integer stepCount;

    @Schema(description = "错误信息（如果失败）")
    private String errorMessage;

    @Schema(description = "执行历史（调试信息）")
    private List<String> executionHistory;

    @Schema(description = "工具调用记录（调试信息）")
    private List<ToolCallRecord> toolCalls;

    @Schema(description = "结果分析（AI生成）")
    private ResultAnalysis resultAnalysis;

    /**
     * 工具调用记录
     */
    @Data
    @Builder
    @NoArgsConstructor
    @AllArgsConstructor
    @Schema(description = "工具调用记录")
    public static class ToolCallRecord {
        @Schema(description = "步骤序号", example = "1")
        private Integer step;

        @Schema(description = "工具名称", example = "rewriteQuery")
        private String toolName;

        @Schema(description = "工具输入")
        private String input;

        @Schema(description = "工具输出")
        private String output;

        @Schema(description = "调用时间戳", example = "1699000000000")
        private Long timestamp;
    }

    /**
     * 结果分析信息
     */
    @Data
    @Builder
    @NoArgsConstructor
    @AllArgsConstructor
    @Schema(description = "查询结果智能分析")
    public static class ResultAnalysis {
        @Schema(description = "自然语言描述", example = "查询返回10条商品记录，销售额范围在1000-5000元之间...")
        private String naturalDescription;

        @Schema(description = "图表推荐", example = "建议使用：柱状图（适合分类对比）")
        private String chartRecommendation;

        @Schema(description = "数据洞察", example = "[\"⚠️ 字段'price'有10%的空值\", \"📊 数据量较大\"]")
        private List<String> insights;

        @Schema(description = "记录统计数量")
        private Integer recordCount;

        @Schema(description = "字段统计数量")
        private Integer fieldCount;
    }
}

